<template>
  <div class="app-container">
    <el-row :gutter="10">
      <el-col :xs="12" :sm="12" :md="8" :lg="9" :xl="10">
        <el-form @submit.native.prevent>
          <el-form-item :label="$t('lat')">
            <el-input v-model="lat" :placeholder="$t('lat')" />
          </el-form-item>
          <el-form-item :label="$t('lng')">
            <el-input v-model="lng" :placeholder="$t('lng')" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="latlngLocal"> {{ $t('latlng') }} </el-button>
          </el-form-item>
        </el-form>
        <el-form @submit.native.prevent>
          <el-form-item :label="$t('mcc')">
            <el-input v-model="mcc" :placeholder="$t('mcc')" />
          </el-form-item>
          <el-form-item :label="$t('mnc')">
            <el-input v-model="mnc" :placeholder="$t('mnc')" />
          </el-form-item>
          <el-form-item :label="$t('lac')">
            <el-input v-model="lac" :placeholder="$t('lac')" />
          </el-form-item>
          <el-form-item :label="$t('ci')">
            <el-input v-model="ci" :placeholder="$t('ci')" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="baseStationLocal"> {{ $t('baseStation')}}{{$t('local') }} </el-button>
          </el-form-item>
        </el-form>
      </el-col>
      <el-col :xs="12" :sm="12" :md="16" :lg="15" :xl="14">
        <json-editor v-model="resData" />
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { latlngLocal, baseStationLocal } from '@/api/iot/iotDeviceLocalApi'
import JsonEditor from '@/components/JsonEditor'
import { failureNotice } from '@/util/common'
export default {
  name: 'LocalTool',
  components: {
    JsonEditor
  },
  data() {
    return {
      resData: {},
      lat: null,
      lng: null,
      mcc: null,
      mnc: null,
      lac: null,
      ci: null
    }
  },
  methods: {
    latlngLocal() {
      latlngLocal({
        lat: this.lat,
        lng: this.lng
      }).then(res => {
        const { code, data } = res
        if (code === '200') {
          this.resData = data
        }
      })
    },
    baseStationLocal() {
      baseStationLocal({
        mcc: this.mcc,
        mnc: this.mnc,
        lac: this.lac,
        ci: this.ci
      }).then(res => {
        const { code, data, msg } = res
        if (code === '200') {
          this.resData = data
        } else {
          failureNotice(this, msg)
        }
      })
    }
  }
}
</script>


